<template>
  <view class="detail_wrap">
    <!-- 图片开始 -->
    <view class="img_wrap">
      <image :src="imgUrl" mode="aspectFill" lazy-load @click="handTest" />
    </view>
    <view
      class="cu-btn bg-pink lg shadow"
      style="position: absolute;right: 0upx;top: 0upx;"
    >{{type}}</view>
    <!-- 图片结束 -->
    <view class="cu-card">
		<view class=" cu-item bg-white shadow">
			<view class="segn_wrap">
			  <uni-segmented-control
			    :current="current"
			    :values="items.map(v=>v.title)"
			    @clickItem="handleClick"
			    style-type="text"
			    active-color="#feb2b2"
			  ></uni-segmented-control>
			</view>			
		</view>
	</view>


    <!-- 组件显示 -->
    <view class="segn_content">
      <view v-if="current === 0">
        <!-- <course-desc :coursesList="coursesList" @handLF="liekandfollow"></course-desc> -->
        <course-desc :myId="id"></course-desc>
      </view>
      <view v-if="current === 1">
        <course-comments :myId="id"></course-comments>
      </view>
    </view>
  </view>
</template>

<script>
import courseComments from "./course-comments/index";
import courseDesc from "./course-desc/index";
import { uniSegmentedControl } from "@dcloudio/uni-ui";
export default {
  //name: "basics",
  components: {
    courseComments,
    courseDesc,
    uniSegmentedControl
  },
  data() {
    return {
      coursesList: {},
      id: 0,
      imgUrl: "",
      type: "",
      current: 0,
      items: [{ title: "简介" }, { title: "评论" }]
    };
  },
  methods: {
    handleClick(e) {
      if (this.current != e.currentIndex) {
        this.current = e.currentIndex;
      }
    }
  },
  onLoad(option) {
    //console.log(option);
    this.id = option.id;
    if (option.imgUrl != null && option.type != null) {
      this.imgUrl = option.imgUrl;
      this.type = option.type;
    } else {
      this.request({
        url:
          this.apiServer +
          "/courses/findCourseByIdAndUId?id=" +
          this.id +
          "&uId=" +
          uni.getStorageSync("user").id
      }).then(res => {
        this.imgUrl = res.data.imgUrl;
        this.type = res.data.type;
      });
    }

    //this.id = 1;
    //this.getCourse();
  },
  onUnload() {
    console.log("onUnload");
    // uni.$on("liekandfollow", function(data) {
    //   console.log("监听到事件来自 update ，携带参数 msg 为：" + data);
    // });
  }
};
</script>

<style lang="scss" scoped>
.detail_wrap {
  .img_wrap {
    image {
    }
  }

  .segn_wrap {
  }
  .segn_content {
  }
}
</style>